// pages/products_all/products_all.js
// 语言包
var chi = require('../../utils/Chinese.js')
var eng = require("../../utils/English.js")
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    language:'',
    // 语言包对象
    content: '',
    inputValue: '',
    // 产品左侧
    nav:[{id:'0',txt:'法布芮糖浆'},{id:'1',txt:'法布芮果泥'},{id:'2',txt:'鸡尾酒樱桃'},{id:'3',txt:'鸡尾酒樱桃'},{id:'4',txt:'鸡尾酒樱桃'},{id:'5',txt:'鸡尾酒樱桃'},{id:'6',txt:'鸡尾酒樱桃'},{id:'7',txt:'鸡尾酒樱桃'},{id:'8',txt:'鸡尾酒樱桃'},{id:'9',txt:'鸡尾酒樱桃'},{id:'10',txt:'鸡尾酒樱桃'},{id:'11',txt:'鸡尾酒樱桃'},{id:'12',txt:'鸡尾酒樱桃'},{id:'13',txt:'鸡尾酒樱桃'},{id:'14',txt:'鸡尾酒樱桃'},{id:'15',txt:'鸡尾酒樱桃'},],
    // 产品信息
    all_list:[[{id:'0',url:'../../img/tui_03.jpg',name:'CARAMEL GOURMET SYRUP',price:'120000',specifi:'glass bottles 300ml'},{id:'1',url:'../../img/tui_03.jpg',name:'我是第一类',price:'127',specifi:'glass bottles 300ml'},{id:'2',url:'../../img/tui_03.jpg',name:'我是第一类',price:'127',specifi:'glass bottles 300ml'},{id:'3',url:'../../img/tui_03.jpg',name:'我是第一类',price:'127',specifi:'glass bottles 300ml'},{id:'4',url:'../../img/tui_03.jpg',name:'我是第一类',price:'127',specifi:'glass bottles 300ml'},{id:'5',url:'../../img/tui_03.jpg',name:'我是第一类',price:'127',specifi:'glass bottles 300ml'},{id:'6',url:'../../img/tui_03.jpg',name:'我是第一类',price:'127',specifi:'glass bottles 300ml'},{id:'7',url:'../../img/tui_03.jpg',name:'我是第一类',price:'127',specifi:'glass bottles 300ml'},{id:'8',url:'../../img/tui_03.jpg',name:'我是第一类',price:'127',specifi:'glass bottles 300ml'},{id:'9',url:'../../img/tui_03.jpg',name:'我是第一类',price:'127',specifi:'glass bottles 300ml'},{id:'10',url:'../../img/tui_03.jpg',name:'我是第一类',price:'127',specifi:'glass bottles 300ml'},{id:'11',url:'../../img/tui_03.jpg',name:'我是第一类',price:'127',specifi:'glass bottles 300ml'}],[{id:'1',url:'../../img/tui_03.jpg', name:'我是第二类',price:'127',specifi:'glass bottles 300ml'}],[{id:'2',url:'../../img/tui_03.jpg', name:'我是第三类',price:'127',specifi:'glass bottles 300ml'}]],
    winWidth: 0,
    winHeight: 0,
    currentTab: 0,
  },

  // 搜索事件
  search:function(){
    var txt = this.data.inputValue
    console.log(txt)
  },
  bindKeyInput: function (e) {
    this.setData({
      inputValue: e.detail.value
    })
  },
  //  tab切换逻辑
  swichNav: function( e ) {
      var that = this;
     
      if( this.data.currentTab === e.currentTarget.dataset.current ) {
          return false;
      } else {
          that.setData( {
              currentTab: e.currentTarget.dataset.current
          })
      }
      console.log(e)
      console.log(that.data.currentTab)
  },

  bindChange: function( e ) {
      var that = this;
      that.setData( { currentTab: e.currentTarget.dataset.current });
  },
  // 页面跳转
  product:function(e){
    console.log(e.currentTarget.dataset.id)
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../comm/comm',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    console.log(that.data.all_list)
    this.setData({
      language:app.data.language, 
    })
    var lastLanuage = that.data.language
    if(lastLanuage == 'zh_CN'){
      that.setData({
        content: chi.content,
      })
      wx.setNavigationBarTitle({
        title: '产品中心' 
      })
    }else if(lastLanuage == 'zh_EN'){
      console.log('yingwen')
      that.setData({
        content: eng.content,
      })
      // 修改导航标题
      wx.setNavigationBarTitle({
        title: 'Product Center' 
      })
    }
    // 页面tab切换 ==================
       /**
         * 获取当前设备的宽高
         */
        wx.getSystemInfo( {

          success: function( res ) {
              that.setData( {
                  winWidth: res.windowWidth,
                  winHeight: res.windowHeight
              });
          }

      });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this
    this.setData({
      language:app.data.language, 
    })
    var lastLanuage = that.data.language
    if(lastLanuage == 'zh_CN'){
      that.setData({
        content: chi.content,
      })
      wx.setNavigationBarTitle({
        title: '产品中心' 
      })
    }else if(lastLanuage == 'zh_EN'){
      console.log('yingwen')
      that.setData({
        content: eng.content,
      })
      // 修改导航标题
      wx.setNavigationBarTitle({
        title: 'Product Center' 
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})